home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / contrib / libgrx / ndrivers / pieces / addmode.c next >
Encoding:
C/C++ Source or Header  |  1993-12-06  |  2.8 KB  |  92 lines

  1. /**
  2.  ** ADDMODE.C ---- code fragments to manipulate the mode tables
  3.  **
  4.  ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5.  ** Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6.  ** Copyright (C) 1993 Grzegorz Mazur, gbm@ii.pw.edu.pl
  7.  **
  8.  ** This file is distributed under the terms listed in the document
  9.  ** "copying.dj", available from DJ Delorie at the address above.
  10.  ** A copy of "copying.dj" should accompany this file; if not, a copy
  11.  ** should be available from where this file was obtained.  This file
  12.  ** may not be distributed without a verbatim copy of "copying.dj".
  13.  **
  14.  ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15.  ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16.  **/
  17.  
  18. struct mode_table_desc {
  19.     GrModeEntry *table;
  20.     int cur_size;
  21.     int max_size;
  22. };
  23.  
  24. struct mode_table_desc text_table_desc = {
  25.     text_mode_table,
  26.     (-1),
  27.     sizeof(text_mode_table) / sizeof(GrModeEntry)
  28. };
  29.  
  30. struct mode_table_desc graphics_table_desc = {
  31.     graphics_mode_table,
  32.     (-1),
  33.     sizeof(graphics_mode_table) / sizeof(GrModeEntry)
  34. };
  35.  
  36. void tblcopy(GrModeEntry *to,GrModeEntry *from,int count)
  37. {
  38.     _DI = FP_OFF(to);
  39.     _SI = FP_OFF(from);
  40.     _CX = count * (sizeof(GrModeEntry) / sizeof(short));
  41.     _ES = _DS;
  42.     asm cld;
  43.     if(_DI > _SI) {
  44.         _AX = _CX + _CX - sizeof(short);
  45.         asm add di,ax;
  46.         asm add si,ax;
  47.         asm std;
  48.     }
  49.     asm rep movsw;
  50.     asm cld;
  51. }
  52.  
  53. void insert_mode_entry(struct mode_table_desc *dsc,int w,int h,unsigned int colors,int BIOSno,int setup)
  54. {
  55.     GrModeEntry *mdp = dsc->table;
  56.     int copy,pos;
  57.  
  58.     if(dsc->cur_size < 0) {
  59.         for(pos = 1; mdp->width > 0; mdp++) pos++;
  60.         dsc->cur_size = pos;
  61.         mdp = dsc->table;
  62.     }
  63.     if(dsc->cur_size < dsc->max_size) {
  64.         for(pos = 0; mdp->width > 0; pos++,mdp++) {
  65.         if(mdp->number_of_colors > colors) break;
  66.         if(mdp->number_of_colors < colors) continue;
  67.         if((mdp->width == w) && (mdp->height == h)) {
  68.             /* mode already exists */
  69.             /* give priority to modes with standard setup */
  70.             if((setup == 0) || (mdp->mode.vdr.BIOS_mode == UNSUP)) {
  71.             mdp->mode.vdr.BIOS_mode = BIOSno;
  72.             mdp->mode.vdr.custom_setup_index = setup;
  73.             }
  74.             return;
  75.         }
  76.         if((mdp->width >= w) && (mdp->height >= h)) break;
  77.         }
  78.         copy = dsc->cur_size - pos;
  79.         if(copy > 0) tblcopy((mdp + 1),mdp,copy);
  80.         mdp->width  = w;
  81.         mdp->height = h;
  82.         mdp->number_of_colors = colors;
  83.         mdp->mode.vdr.BIOS_mode = BIOSno;
  84.         mdp->mode.vdr.custom_setup_index = setup;
  85.         dsc->cur_size++;
  86.     }
  87. }
  88.  
  89. #define add_text_mode(W,H,PL,BNO,SUP)        insert_mode_entry(&text_table_desc,W,H,PL,BNO,SUP)
  90. #define add_graphics_mode(W,H,PL,BNO,SUP)   insert_mode_entry(&graphics_table_desc,W,H,PL,BNO,SUP)
  91.  
  92.